package org.example.controller;

import jakarta.annotation.Resource;
import org.example.entity.R;
import org.example.pojo.Emp;
import org.example.service.IEmpService;
import org.springframework.web.bind.annotation.*;

/**
 * @author TonySong
 * @date 2024/4/26 0026
 * @time 9:54
 */
@RestController
@RequestMapping("/emp")
public class EmpController {

    @Resource
    private IEmpService empService;

    @GetMapping("/")
    public R getEmp(){
        return R.success(empService.getAllEmps());
    }

    @PostMapping("/")
    public R save(@RequestBody Emp emp){
        try {
            this.empService.saveEmp(emp);
        }catch (Exception e){
            return R.error();
        }
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Long id) {
        try {
            this.empService.deleteEmp(id);
        } catch (Exception e) {
            return R.error();
        }
        return R.ok();
    }



}
